/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Penjualan;

import java.sql.PreparedStatement;
import javax.swing.*;

/**
 *
 * @author IDIFIDI
 */
public class Penjualan {

    /**
     * @return the hargaPulsa
     */
    public static int getHargaPulsa() {
        return hargaPulsa;
    }

    /**
     * @param aHargaPulsa the hargaPulsa to set
     */
    public static void setHargaPulsa(int aHargaPulsa) {
        hargaPulsa = aHargaPulsa;
    }

    private String noPenjualan;
    private String waktu;
    private String noHp;
    private String provider;
    private int nominal;
    private int harga;
    private String status;
    private String idUser;
    private static String kodeAwal = "MAFYJ-";
    private static int hargaPulsa=2000;
    private long stok;
    public Penjualan() {
//        try
//        {
//            setNominal(nominal);
//            setHarga(harga);
//        }
//        catch(Exception e)
//        {
//            JOptionPane.showMessageDialog(null, "ERROR : "+e.getMessage());
//        }
    }

    public static void setKodeAwal(String kode) {
        kodeAwal = kode;
    }

    public static String getKodeAwal() {
        return kodeAwal;
    }

    public void setNoPenjualan(String noPenjualan) throws Exception {
        if (noPenjualan.isEmpty()) {
            throw new Exception("Nomor Penjualan tidak boleh kosong!");
        } else if (noPenjualan.equals("")) {
            throw new Exception("Nomor Penjualan harus diisi!");
        } else if (noPenjualan.equals("MAFYJ-")) {
            throw new Exception("Nomor Penjualan salah, masukkan nomor urut!");
        } else if (noPenjualan.matches("MAFYJ-[a-zA-Z\\s]*")) {
            throw new Exception("Nomor penjualan salah, setelah MAFYJ- masukkan nomor urut berupa angka!");
        } else if (noPenjualan.contains("MAFYJ-")) {
            this.noPenjualan = noPenjualan;
        } else {
            throw new Exception("Nomor Penjualan salah, harap isikan kode awal : MAFYJ-");
        }
    }

    public String getNoPenjualan() {
        return noPenjualan;
    }

    public void setWaktu(String waktu) {
        this.waktu = waktu;
    }

    public String getWaktu() {
        return waktu;
    }

    public void setNoHp(String noHP) throws Exception {
        if (noHP.isEmpty()) {
            throw new Exception("Nomor Handphone harap diisi!");
        } else if (noHP.equals("")) {
            throw new Exception("Nomor Handphone harap diisi!");
        } else if (noHP.matches("[a-zA-Z\\s]*")) {
            throw new Exception("Input Nomor handphone dengan angka!");
        } else {
            this.noHp = noHP;
        }
    }

    public String getNoHp() {
        return noHp;
    }

    public void setProvider(String provider) throws Exception {
        if (provider.equalsIgnoreCase("-pilih provider-")) {
            throw new Exception("Pilih provider terlebih dahulu!");
        } else {
            this.provider = provider;
        }
    }

    public String getProvider() {
        return provider;
    }

//    public void setNominal(int nominal) throws Exception
//    {
//        if(nominal<0)
//        {
//            throw new Exception("Inputan harus bernilai positif");
//        }
//        else if(nominal==0)
//        {
//            throw new Exception("Nominal tidak boleh bernilai nol!");
//        }
//        else if(nominal<5000)
//        {
//            throw new Exception("Nominal yang dimasukkan tidak boleh kurang dari 5000!");
//        }
//        else
//            this.nominal=nominal;
//    }
    public void setNominal(String nominal) throws Exception {
        if (nominal.isEmpty()) {
            throw new Exception("Nominal harus diisi!");
        } else if (nominal.equals("")) {
            throw new Exception("Nominal tidak boleh kosong!");
        } else if (nominal.matches("[a-zA-Z\\s-]*")) {
            throw new Exception("Nominal tidak boleh berisi huruf");
        } else {
            try {
                this.nominal = Integer.parseInt(nominal);
            } catch (NumberFormatException ex) {
                throw new NumberFormatException("terdapat huruf pada nominal!");
            }
        }
    }

    public int getNominal() {
        return nominal;
    }

//    public void setHarga(int harga) throws Exception
//    {
//        if(harga<0)
//            throw new Exception("Inputan harus bernilai positif");
//        else if(harga==0)
//            throw new Exception("Harga tidak boleh bernilai nol!");
//        else if(harga<5000)
//            throw new Exception("Harga yang dimasukkan minimal 5000!");
//        else
//            this.harga=harga;
//    }
    public void setHarga(String harga) throws Exception {
        if (harga.isEmpty()) {
            throw new Exception("Harga harus diisi!");
        } else if (harga.equals("")) {
            throw new Exception("Harga harus diisi, tidak boleh kosong!");
        } else if (harga.matches("[a-zA-Z\\s]*")) {
            throw new Exception("Harga tidak boleh diisi dengan huruf!");
        } else {
            try {
                this.harga = Integer.parseInt(harga);
            } catch (NumberFormatException ex) {
                throw new NumberFormatException("terdapat huruf pada harga!");
            }
        }
    }



    public int getHarga() {
        return harga;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public void setIdUser(String id) {
        this.idUser = id;
    }

    public String getIdUser() {
        return idUser;
    }

    /**
     * @return the stok
     */
    public long getStok() {
        return stok;
    }

    /**
     * @param stok the stok to set
     */
    public void setStok(long stok) {
        this.stok = stok;
    }
}
